package com.zhongyu.controller;

import com.zhongyu.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//控制层全局异常处理器
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public ResultVo handleException(RuntimeException ex){
      //  log.error(ex.getMessage(),ex);
        if (ex instanceof UnknownAccountException){
            log.error("该用户没有授权!",ex);
        }else {
            log.error("全局异常处理器捕获到异常!",ex);
        }
        return ResultVo.failure("用户操作失败！");
    }

}
